package cn.chenxiejia;

/**
 * @version : V1.0
 * @program: maven
 * @ClassName: Animal
 * @Description:
 * @Author: chenxiejia
 * @Date: 2022/2/9 15:34
 */

public class Animal {
    //    @AnimalAdress(adress = Enum1.内蒙)
//    @AnimalName(name = "天天")
    public static void main(String[] args) {
        //查看类上的注解
        var a = Animal1.class;
        if (a.isAnnotationPresent(AnimalName.class)) {
            var an = a.getAnnotation(AnimalName.class);
            System.out.println(an.name());
        }
        try {
            //查看声明属性上的注解
            var b = a.getDeclaredField("name");
            if (b.isAnnotationPresent(AnimalName.class)) {
                System.out.println(b.getAnnotation(AnimalName.class).name());
            }

        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
        try {
            //查看声明方法上的注解
            var c = a.getDeclaredMethod("show");
            if (c.isAnnotationPresent(AnimalName.class)) {
                System.out.println(c.getAnnotation(AnimalName.class).name());
            }
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }


//        try {
//            var an = Animal.class.getMethod("main", String[].class);
//
//            System.out.println(an.getAnnotation(AnimalName.class).name());
//            System.out.println(an.getAnnotation(AnimalAdress.class).adress());
//        } catch (NoSuchMethodException e) {
//            e.printStackTrace();
//        }
    }

}
